package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> selectAll(){
        List<NursingPlanVo> list = nursingPlanService.selectAll();
        return success(list);
    }


    @GetMapping("/search")
    @ApiOperation(value = "分页查询护理计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理计划名称", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "integer", paramType = "query", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "integer", paramType = "query", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "integer", paramType = "query", required = false)
    })
    public ResponseResult<PageResponse<NursingPlanVo>> selectByPage(String name, Integer pageNum,
                                                                             Integer pageSize, Integer status){
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.selectByPage(name,pageNum,pageSize,status);
        return success(pageResponse);
    }


    @PostMapping
    @ApiOperation(value = "新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.selectById(id);
        return success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新护理计划")
    public ResponseResult updateNursingPlan(@PathVariable Long id,@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateNursingPlan(id,nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Long id){
        nursingPlanService.deleteNursingPlan(id);
        return success();
    }


    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理计划")
    public ResponseResult isForbidden(@PathVariable Integer id, @PathVariable Integer status){
        nursingPlanService.isForbidden(id,status);
        return success();
    }
}
